// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init();
const db = cloud.database();

// 云函数入口函数
// 获取首页菜谱列表
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext();
  let type = event.type;
  let result = await db.collection("classify").where({
    type
  }).get();

  let classify = null;
  let edit = false;
  if(result.data.length){
    classify = result.data[0];
    edit = (Boolean(classify.openid) && (classify.openid === wxContext.OPENID));
  }

  return {
    code:200,
    result:classify,
    edit,
    res:result,
    event
    // event,
    // openid: wxContext.OPENID,
    // appid: wxContext.APPID,
    // unionid: wxContext.UNIONID,
  }
}